<%@page import="cn.jhc.dao.NewMsgDAO"%>
<%@page import="cn.jhc.dao.MsgDao"%>
<%@page import="cn.jhc.bean.MsgBean"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/houtai.css"></link>
<script type="text/javascript">
	function MM_popupMsg(msg) {
		alert(msg);
	}
</script>
<title>社团管理平台</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int titleCount = 5;
		int MsgCount;
	%>
	<div id="wrapper">
		<jsp:include page="./houtai_header.jsp"></jsp:include>
		<div id="left">
			<a href="houtai_taolunqu.jsp">灌水区</a> <a
				href="houtai_taolunquAct.jsp">活动讨论区</a> <a
				href="houtai_taolunquNews.jsp">新闻讨论区</a> <a
				href="houtai_taolunquMusic.jsp">乐曲交流区</a>
		</div>
		<div id="right">
			<div id="right_top">
				<a>所在位置： 论坛信息>新闻讨论区</a>
			</div>
			<%
				ArrayList<MsgBean> m = new ArrayList<MsgBean>();
				NewMsgDAO dao = new NewMsgDAO();
				dao.setCon(ConnectionFactory.getConnection());
				m = dao.getAllMessages(CurrentPage, titleCount);
				request.setAttribute("title", m);
			%>
			<%
				ArrayList<MsgBean> b = new ArrayList<MsgBean>();
				NewMsgDAO dao3 = new NewMsgDAO();
				dao3.setCon(ConnectionFactory.getConnection());
				b = dao3.getBetterMessages();
				request.setAttribute("better", b);
			%>
			<%
				ArrayList<MsgBean> t = new ArrayList<MsgBean>();
				MsgDao dao4 = new MsgDao();
				dao4.setCon(ConnectionFactory.getConnection());
				t = dao4.getTopMessages();
				request.setAttribute("top", t);
			%>
			<%
				NewMsgDAO dao2 = new NewMsgDAO();
				dao2.setCon(ConnectionFactory.getConnection());
				intPageCount = dao2.getCount(titleCount);
				if (intPageCount == 0) {
					CurrentPage = 1;
					intPageCount = 1;
				} else {
					if (CurrentPage > intPageCount)
						CurrentPage = intPageCount;
				}
			%>
			<div id="right_news">
				<table width="100%">
					<tr>
						<th height="25">标题</th>
						<th>时间</th>
						<th>发表</th>
						<th>回复</th>
						<th>操作</th>
						<th>设置</th>
					</tr>
					<%
						if (CurrentPage == 1) {
					%>
					<%
						ArrayList list = (ArrayList) request.getAttribute("top");
							if (list != null) {
								for (int i = 0; i < list.size(); i++) {
									MsgBean top = (MsgBean) list.get(i);
					%>
					<tr>
						<td width="70%" height="25"><a
							href="showmessages.jsp?id=<%=top.getId()%>">[置顶]<%=top.getTitle()%></a>
						<td><div align="center"><%=top.getDate()%></div></td>
						<td><div align="center"><%=top.getDisplayname()%></div></td>
						<%
							MsgDao dao5 = new MsgDao();
										dao5.setCon(ConnectionFactory.getConnection());
										MsgCount = dao5.getMsgCount(top.getId());
						%>
						<td><div align="center"><%=MsgCount%></div></td>
						<td><div align="center">
								<a href="./deleteTitle.do?id=<%=top.getId()%>"
									onclick="MM_popupMsg('删除成功！')">删除</a>
							</div></td>
						<td><div align="center">
								<a>无</a>
							</div></td>
					</tr>
					<%
						}
							}
					%>
					<%
						ArrayList bet = (ArrayList) request.getAttribute("better");
							if (bet != null) {
								for (int i = 0; i < bet.size(); i++) {
									MsgBean bett = (MsgBean) bet.get(i);
					%>
					<tr>
						<td width="70%" height="25"><a
							href="showNewsmessages.jsp?id=<%=bett.getId()%>">[精华]<%=bett.getTitle()%></a>
						<td><div align="center"><%=bett.getDate()%></div></td>
						<td><div align="center"><%=bett.getDisplayname()%></div></td>
						<%
							NewMsgDAO dao5 = new NewMsgDAO();
										dao5.setCon(ConnectionFactory.getConnection());
										MsgCount = dao5.getMsgCount(bett.getId());
						%>
						<td><div align="center"><%=MsgCount%></div></td>
						<td><div align="center">
								<a href="./deleteNewsTitle.do?id=<%=bett.getId()%>"
									onclick="MM_popupMsg('删除成功！')">删除</a>
							</div></td>
						<td><div align="center">
								<a href="./updateNewsNo.do?id=<%=bett.getId()%>"
									onclick="MM_popupMsg('取消成功！')">取消</a>
							</div></td>
					</tr>
					<%
						}
							}
					%>
					<%
						}
					%>
					<%
						ArrayList ti = (ArrayList) request.getAttribute("title");
						if (ti != null) {
							for (int i = 0; i < ti.size(); i++) {
								MsgBean tit = (MsgBean) ti.get(i);
					%>
					<tr>
						<td width="70%" height="25"><a
							href="showNewsmessages.jsp?id=<%=tit.getId()%>">[普通]<%=tit.getTitle()%></a>
						<td><div align="center"><%=tit.getDate()%></div></td>
						<td><div align="center"><%=tit.getDisplayname()%></div></td>
						<%
							NewMsgDAO dao5 = new NewMsgDAO();
									dao5.setCon(ConnectionFactory.getConnection());
									MsgCount = dao5.getMsgCount(tit.getId());
						%>
						<td><div align="center"><%=MsgCount%></div></td>
						<td><div align="center">
								<a href="./deleteNewsTitle.do?id=<%=tit.getId()%>"
									onclick="MM_popupMsg('删除成功！')">删除</a>
							</div></td>
						<td><div align="center">
								<a href="./updateNewsEssence.do?id=<%=tit.getId()%>"
									onclick="MM_popupMsg('设置成功！')">精华帖</a>
							</div></td>
					</tr>
					<%
						}
						}
					%>
				</table>
				<div align="right">
					<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
					</a> <a href="houtai_taolunquNew.jsp?page=<%=1%>">首页</a>
					<%
						if (CurrentPage > 1) {
					%>
					<a href="houtai_taolunquNew.jsp?page=<%=CurrentPage - 1%>">上一页</a>
					<%
						} else {
					%>
					上一页
					<%
						}
					%>
					<%
						if (CurrentPage >= intPageCount) {
					%>
					下一页
					<%
						} else {
					%>
					<a href="houtai_taolunquNew.jsp?page=<%=CurrentPage + 1%>">下一页</a>
					<%
						}
					%>
					<a href="houtai_taolunquNew.jsp?page=<%=intPageCount%>">末页</a>
				</div>
				<div id="button">
					<form method="post" action="./houtai_addTopTitle.jsp">
						<input type="submit" value="发布置顶帖"></input>
					</form>
				</div>
			</div>
		</div>
	</div>
</body>
</html>